<template>
	<view class="joe-body">
		<view>
			<joe-game-list @onStart="bindGamePlay" @onDown="bindGameDown" v-model="gameList"></joe-game-list>
		</view>
	</view>
</template>

<script>
	import joeGameList from '@/components/joe-game/game-list.vue'
	import {api_mygame,api_game_paly,api_down_game} from '@/api/index.js'
	import service from '@../../service.js'
	export default {
		components:{
			joeGameList
		},
		data() {
			return {
				gameList: [],
				page:0,
				rows:10,
				group_id:0,
				member_id:0,
			}
		},
		methods: {
			//游戏开始
			bindGamePlay(e){
				let member_id = service.getUsers().member_id
				api_game_paly(member_id,e.game_id).then(res=>{
					let play = escape(res.data.data.url)
					uni.navigateTo({
						url: '../game/game-play?gamePlay=' +  play
					})
				})				
			},
			//游戏下载
			bindGameDown(game){
				let member_id = service.getUsers().member_id
				api_down_game(game.game_id, member_id).then(res => {
					uni.navigateTo({
						url: '../game/game-play?type=down&gamePlay=' + escape(game.url)
					})
				})				
			}
		},
		onReachBottom:function(){
			uni.showToast({
				title:'正在加载'
			})
			this.page++
			api_mygame(this.member_id,this.page,this.rows).then(res => {
				//this.gameList = res.data.data.list
				let list = res.data.data.list
				list.forEach((item,index)=>{
					this.gameList.push(item)
				})
				//this.gameList.push(res.data.data.list)
			})
		},
		onLoad:function(param){
		    this.member_id = param.member_id
			api_mygame(this.member_id,this.page,this.rows).then(res=>{
				this.gameList = res.data.data.list
			})
		}
	}
</script>

<style lang="scss">
	view {
		width: 100%;
	}
	.joe-body{
		padding: 15upx;
	}
</style>
